home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
PASCAL
/
1372.ZIP
/
PIBCAT.ARC
/
PIBCATM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-10-28
|
15KB
|
321 lines
(*----------------------------------------------------------------------*)
(* Display_MD_Contents --- Display contents of library (.MD) file *)
(*----------------------------------------------------------------------*)
PROCEDURE Display_MD_Contents( MDFileName : AnyStr );
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Display_MD_Contents *)
(* *)
(* Purpose: Displays contents of a library file (.MD file) *)
(* *)
(* Calling sequence: *)
(* *)
(* Display_MD_Contents( MDFileName : AnyStr ); *)
(* *)
(* MDFileName --- name of .MD file whose contents *)
(* are to be listed. *)
(* *)
(* Calls: *)
(* *)
(* Aside from internal subroutines, these routines are required: *)
(* *)
(* Dir_Convert_Date_And_Time *)
(* --- convert DOS packed date/time to string*)
(* Open_File --- open a file *)
(* Close_File --- close a file *)
(* Entry_Matches --- Perform wildcard match *)
(* Display_Page_Titles *)
(* --- Display titles at top of page *)
(* DUPL --- Duplicate a character into a string *)
(* *)
(*----------------------------------------------------------------------*)
TYPE
Array4 = ARRAY[1..4] OF CHAR;
(* STRUCTURED *) CONST
ValidSig : Array4 = 'MDmd' (* Signature to verify mdcd file *);
(*----------------------------------------------------------------------*)
(* Map of MD file entry header *)
(*----------------------------------------------------------------------*)
TYPE
MD_Entry_Type = RECORD (* Header for each compressed file *)
Signature : Array4 (* file/header signature (MDmd) *);
ReleaseLevel : BYTE (* compress version *);
HeaderType : BYTE (* header type. only type 1 for now *);
HeaderSize : WORD (* size of this header in bytes *);
UserInfo : WORD (* any user info desired *);
Reserved1 : WORD (* future use and upward compatablty *);
Reserved2 : LONGINT (* future use and upward compatablty *);
Reserved3 : ARRAY[1..8] OF BYTE (* future use and upward compatablty *);
CompressType : BYTE (* type of compression *);
OrigFileSize : LONGINT (* original file size in bytes *);
CompFileSize : LONGINT (* compressed file size in bytes *);
FileAttr : WORD (* original file attribute *);
FileDate : LONGINT (* original file date/time *);
FileCRC : WORD (* file crc *);
FileName : STRING[12] (* file name *);
PathName : DirStr (* original drive\path *);
END;
VAR
MDFile : FILE (* MD file to be read *);
MD_Entry : MD_Entry_Type (* Header for one file in MD file *);
MD_Pos : LONGINT (* Current byte offset in MD file *);
Bytes_Read : INTEGER (* # bytes read from MD file *);
Ierr : INTEGER (* Error flag *);
Do_Blank_Line : BOOLEAN (* TRUE to print blank line *);
(*----------------------------------------------------------------------*)
(* Get_Next_MD_Entry --- Get next header entry in MD file *)
(*----------------------------------------------------------------------*)
FUNCTION Get_Next_MD_Entry( VAR MDEntry : MD_Entry_Type;
VAR Error : INTEGER ) : BOOLEAN;
(*----------------------------------------------------------------------*)
(* *)
(* Function: Get_Next_MD_Entry *)
(* *)
(* Purpose: Gets header information for next file in MD file *)
(* *)
(* Calling sequence: *)
(* *)
(* OK := Get_Next_MD_Entry( VAR MDEntry : MD_Entry_Type; *)
(* VAR Error : INTEGER ); *)
(* *)
(* MDEntry --- Header data for next file in MD file *)
(* Error --- Error flag *)
(* OK --- TRUE if header successfully found, else FALSE *)
(* *)
(*----------------------------------------------------------------------*)
BEGIN (* Get_Next_MD_Entry *)
(* Assume no error to start *)
Error := 0;
(* Except first time, move to *)
(* next supposed header record in *)
(* MD file. *)
IF ( MD_Pos <> 0 ) THEN
Seek( MDFile, MD_Pos );
(* Read in the file header entry. *)
BlockRead( MDFile, MDEntry, SizeOf( MD_Entry ), Bytes_Read );
Error := 0;
(* If we didn't read enough, assume *)
(* it's the end of the file. *)
IF ( Bytes_Read < SizeOf( MD_Entry ) ) THEN
Error := End_Of_File
(* Check signature. If wrong, then *)
(* file is bad or not an MD file at *)
(* all. *)
ELSE IF ( MDEntry.Signature <> ValidSig ) THEN
Error := Format_Error
ELSE (* Header looks ok -- we got *)
(* the entry data. Position to *)
(* next header. *)
WITH MDEntry DO
MD_Pos := MD_Pos + HeaderSize + CompFileSize;
(* Report success/failure to calling *)
(* routine. *)
Get_Next_MD_Entry := ( Error = 0 );
END (* Get_Next_MD_Entry *);
(*----------------------------------------------------------------------*)
(* Display_MD_Entry --- Display MD file header entry *)
(*----------------------------------------------------------------------*)
PROCEDURE Display_MD_Entry( MD_Entry : MD_Entry_Type );
VAR
SDate : STRING[10];
STime : STRING[12];
I : INTEGER;
FName : AnyStr;
BEGIN (* Display_MD_Entry *)
WITH MD_Entry DO
BEGIN
(* Pick up file name *)
FName := FileName;
(* See if this file matches the *)
(* entry spec wildcard. Exit if *)
(* not. *)
IF Use_Entry_Spec THEN
IF ( NOT Entry_Matches( FName ) ) THEN
EXIT;
(* Make sure room on current page *)
(* for this entry name. *)
(* If enough room, print blank *)
(* line if requested. This will *)
(* only happen for first file. *)
IF Do_Blank_Line THEN
BEGIN
IF ( Lines_Left < 2 ) THEN
Display_Page_Titles
ELSE
BEGIN
WRITELN( Output_File );
DEC( Lines_left );
END;
Do_Blank_Line := FALSE;
END
ELSE
IF ( Lines_Left < 1 ) THEN
Display_Page_Titles;
(* Add '. ' to front if we're *)
(* expanding MDs in main listing *)
IF Expand_Libs_In THEN
Fname := '. ' + Fname;
(* Get date and time of creation *)
Dir_Convert_Date_And_Time( FileDate , SDate , STime );
(* Write out file name, length, date, time *)
WRITE( Output_File , Left_Margin_String, ' ' , FName );
FOR I := LENGTH( FName ) TO 14 DO
WRITE( Output_File , ' ' );
WRITE ( Output_File , OrigFileSize:8, ' ' );
WRITE ( Output_File , SDate, ' ' );
WRITE ( Output_File , STime );
(* Display long file name if requested *)
IF Show_Long_File_Names THEN
IF ( PathName <> '' ) THEN
BEGIN
WRITE( Output_File , ' ', PathName );
WRITE( Output_File , FileName );
END;
(* Terminate output line *)
WRITELN( Output_File );
(* Count lines left on page *)
IF Do_Printer_Format THEN
DEC( Lines_Left );
(* Increment total entry count *)
INC( Total_Entries );
(* Increment total space used *)
Total_ESpace := Total_ESpace + OrigFileSize;
END;
END (* Display_MD_Entry *);
(*----------------------------------------------------------------------*)
BEGIN (* Display_MD_Contents *)
(* Set left margin spacing *)
Left_Margin_String := Left_Margin_String + DUPL( ' ' , Library_Indent );
(* Set file title *)
File_Title := Left_Margin_String + ' MD file: ' + MDFileName;
(* Display MD file's name *)
IF Do_Printer_Format THEN
IF ( Lines_Left < 3 ) THEN
Display_Page_Titles;
(* If we're listing contents at end *)
(* of directory, print MD file name. *)
(* Do_Blank_Line flags whether we *)
(* need to print blank line in entry *)
(* lister subroutine. If listing *)
(* inline, then it's true for the *)
(* first file; otherwise it's false. *)
(* This is to prevent unnecessary *)
(* blank lines in output listing *)
(* when no files are selected from *)
(* a given MD file. *)
IF ( NOT Expand_Libs_In ) THEN
BEGIN
WRITELN( Output_File ) ;
WRITE ( Output_File , File_Title );
DEC( Lines_Left , 2 );
Do_Blank_Line := FALSE;
END
ELSE
Do_Blank_Line := TRUE;
(* Try opening MD file for processing *)
Open_File( MDFileName , MDFile, MD_Pos, Ierr );
(* Issue error message if open fails *)
IF ( Ierr <> 0 ) THEN
BEGIN
WRITELN( Output_File ,
DUPL( ' ' , MAX( 0 , MIN( 12 , 13 - LENGTH( MDFileName ) ) ) ),
' Can''t open .MD file ',MDFileName );
IF Do_Printer_Format THEN
BEGIN
DEC( Lines_Left );
IF ( Lines_Left < 1 ) THEN
Display_Page_Titles;
END;
EXIT;
END
ELSE IF ( NOT Expand_Libs_In ) THEN
BEGIN
WRITELN( Output_File );
WRITELN( Output_File );
(* Count lines left on page *)
IF Do_Printer_Format THEN
DEC( Lines_Left );
END;
(* Loop over entries in MD file *)
WHILE( Get_Next_MD_Entry( MD_Entry , Ierr ) ) DO
Display_MD_Entry( MD_Entry );
(* Print blank line after last entry *)
(* in MD file, if we're expanding *)
(* MD files right after listing them, *)
(* but only if MD file had any entries *)
(* listed. *)
IF ( Expand_Libs_In AND ( NOT Do_Blank_Line ) ) THEN
BEGIN
WRITELN( Output_File );
IF Do_Printer_Format THEN
DEC( Lines_Left );
END;
(* Close MD file *)
Close_File( MDFile );
(* Restore previous left margin spacing *)
Left_Margin_String := DUPL( ' ' , Left_Margin );
(* No file title *)
File_Title := '';
END (* Display_MD_Contents *);